﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace MyChart
{
    /// <summary>
    /// 2D饼图
    /// </summary>
    public class Pie2D : SimpleChart
    {
        /// <summary>
        /// 设置或获取是否显示百分比的值
        /// </summary>
        public bool ShowPercentValues { get; set; }
        /// <summary>
        /// 设置饼图是否支持显示图例
        /// </summary>
        public bool ShowLegend { get; set; }
        /// <summary>
        /// 饼图图例位置
        /// </summary>
        public string _LegendPosition ="RIGHT";
        /// <summary>
        /// 饼图图例显示位置只支持：BOTTOM和RIGHT
        /// </summary>        
        public string LegendPosition { get { return _LegendPosition; } set { _LegendPosition = value; } }
        #region 方法

        /// <summary>
        /// 获取控件的 FusionChart 完整Xml配置字符串
        /// </summary>
        /// <returns>完整的Xml配置字符串</returns>
        public override string GetRenderHtml()
        {
            StringBuilder xml = new StringBuilder();

            xml.Append(@"<chart caption='" + Caption + "'" + (FormatNumber ? " formatNumber='1'" : "") + (ShowPercentValues ? " showPercentValues='1'" : "") + " showLegend='" + (ShowLegend ? 1 : 0) + "' legendPosition='" + LegendPosition + "' subcaption='" + SubCaption + "' animation='" + (Animation ? 1 : 0) + "' isSliced='" + (IsSliced ? 1 : 0) + "'"
                + " palette='" + (int)Theme + "' showLabels='" + (ShowLabels ? 1 : 0) + "' showValues='" + (ShowValues ? 1 : 0) + "'"
                + " numberPrefix='" + NumberPrefix + "' numberSuffix='" + NumberSuffix + "' decimals='" + Decimals + "' decimalPrecision='" + Decimals + "'" + (BgColor.ToArgb() != 0 ? " bgColor='" + BgColor.ToArgb().ToString("X").Remove(0, 2) + "'" : "")
                + " showBorder='" + (ShowBorder ? 1 : 0) + "' baseFont='" + BaseFont.Name + "' baseFontSize='" + BaseFont.Size
                + "'" + (ForeColor.ToArgb() != 0 ? " baseFontColor='" + ForeColor.ToArgb().ToString("X").Remove(0, 2) + "'" : "") + " chartTopMargin='" + MarginTop + "' chartBottomMargin='" + MarginBottom + "'"
                + " chartLeftMargin='" + MarginLeft + "' chartRightMargin='" + MarginRight + "' formatNumberScale='" + (FormatNumberScale ? 1 : 0) + "'>");

            xml.Append(GetItemManagerXmlString());
            xml.Append("</chart>");

            return xml.ToString();
        }

        #endregion
    }
}
